home *** CD-ROM | disk | FTP | other *** search
- Path: erich.triumf.ca!bennett
- From: bennett@erich.triumf.ca (P.Bennett)
- Newsgroups: comp.lang.c
- Subject: Re: Character string
- Date: 11 Apr 1996 07:50 PST
- Organization: TRIUMF: Tri-University Meson Facility
- Distribution: world
- Message-ID: <11APR199607504516@erich.triumf.ca>
- References: <4kil74$8i7@Tandem1.opennet.net.au>
- NNTP-Posting-Host: ftp.triumf.ca
- News-Software: VAX/VMS VNEWS 1.50
-
- In article <4kil74$8i7@Tandem1.opennet.net.au>, george@opennet.net.au (Kenneth H Smith) writes...
- >How do I do a similar statement in C to the Pascal code:
- >
- >If Ch IN ['a','A'] THEN
- >
- >I want to execute a piece of code when a particular character is entered
- >from the keyboard.
- >
- >I know I can use if (ch=='a') && (ch=='A') but was looking for something
- >a little more ellegant.
-
- char ch;
- switch (tolower(ch)) {
- case 'a':
- /* do 'a' task */
- break;
- case 'b':
- /* do 'b' task */
- break;
- ....
- default:
- /* no valid choice... */
- }
-
- Peter Bennett VE7CEI | Vessels shall be deemed to be in sight
- Internet: bennett@triumf.ca | of one another only when one can be
- Packet: ve7cei@ve7kit.#vanc.bc.ca | observed visually from the other
- TRIUMF, Vancouver, B.C., Canada | ColRegs 3(k)
- GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
- or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
-
-
-
-